#include <iostream>
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkImageEncoder.h"
#include "include/core/SkStream.h"
#include "include/core/SkEncodedImageFormat.h"

void computeByteSize(){
    SkBitmap bitmap;
    for (int width: {1, 1000, 1000000}){
        for (int height: {1, 1000, 1000000}){
            SkImageInfo info = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
            bitmap.setInfo(info);
            SkDebugf("width: %7d height: %7d computeByteSize: %13lld minRowBytes: %8d\n", width, height, bitmap.computeByteSize(), info.minRowBytes());
        }
    }
}

int main(){
	SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32Premul(1024, 786));
    bitmap.allocPixels();

    SkCanvas canvas(bitmap);
    canvas.clear(SK_ColorTRANSPARENT);

    SkPaint fontPaint;
    fontPaint.setColor(SK_ColorRED);
    fontPaint.setStyle(SkPaint::kFill_Style);
    fontPaint.setAntiAlias(true);

    sk_sp<SkTextBlob> helloWorld = SkTextBlob::MakeFromString("Welcome to Skia!!", SkFont(nullptr, 64.0f, 1.0f, 0.0f));
    canvas.drawTextBlob(helloWorld.get(), 300, 300, fontPaint);

    SkFILEWStream stream("result.jpg");
    SkEncodeImage(&stream, bitmap, SkEncodedImageFormat::kJPEG, 80);

    computeByteSize();
    return 0;
}
